![]() | ![]() |
%MACRO printout( indata=, var=, group=, boot1=, boot2=, nrun=); proc sort data=&indata out=intmp; by &group; run; proc sql noprint; select distinct rassignt into: groupdiff separated by ' - ' from ridamy.ittbur1 order by rassignt; quit; PROC MEANS DATA= intmp NOPRINT; /* get basic data from original sample */ VAR &var; BY &group; OUTPUT OUT=basic; RUN; ods listing close; proc ttest data=&indata; /* Get Observed Tvalue from original sample */ class &group; var &var; ods output TTests=ttests; run; ods listing; data _null_; set ttests; if Method='Satterthwaite' then do; call symput('rsptobs', tvalue); /* Use tvalue for different variances */ end; run; DATA summary0; /* narrow down to mean and standard error of mean */ SET basic; IF (_STAT_='MEAN' OR _STAT_='STD'); IF _STAT_='STD' THEN &var = &var*&var; KEEP &var; RUN; PROC TRANSPOSE DATA=summary0 OUT=summary0; DATA summary0; SET summary0; CALL SYMPUT('vald', col1-col3); CALL SYMPUT('valf', col2/col4); RUN; DATA combine; /* now form difference of means and F ratios between each pair of samples */ MERGE &boot1 (RENAME=( N=N1 mean=mean1 std= std1)) &boot2 (RENAME=( N=N2 mean=mean2 std= std2)); BY resampleid; diff = mean2-mean1; stddiff=(mean2-mean1)/sqrt(std1*std1/n1+std2*std2/n2); IF (std1 NE 0 AND std2 NE 0) THEN F = std2*std2/std1/std1; IF F<1 THEN F1=1/F;ELSE F1=F; KEEP stddiff diff F F1; RUN; /* This is a dataset with differences of mean and ratios of standard errors for each of the nrun observations */ PROC GCHART DATA=combine; VBAR diff / LEVELS= 50; TITLE "Bootstrap difference in means: variable &var : observed value &vald"; RUN; PROC GCHART DATA=combine (WHERE=(F<16)); VBAR F / LEVELS=50; TITLE "Bootstrap F ratio: variable &var : observed value &valf"; RUN; PROC UNIVARIATE DATA=combine NOPRINT; /* 95% confidence intervals for mean */ VAR diff; OUTPUT OUT=outdiff PCTLPRE=p PCTLPTS=2.5 97.5 5 95; RUN; PROC PRINT DATA=outdiff; TITLE "Bootstrap 95% confidence limit for difference in means (&groupdiff) &var" ; RUN; PROC UNIVARIATE DATA=combine NOPRINT; /*95% confidence intervals for F ratio */ VAR F; OUTPUT OUT=outf PCTLPRE=p PCTLPTS=2.5 97.5 5 95; RUN; PROC PRINT DATA=outf; TITLE "Bootstrap 95% confidence limit for F ratio (&groupdiff) &var" ; RUN; PROC UNIVARIATE DATA=combine NOPRINT; /*95% confidence limit for folded F ratio */ VAR F1; OUTPUT OUT=outf PCTLPRE=p PCTLPTS= 95; RUN; PROC PRINT DATA=outf; TITLE "Bootstrap p-value for folded F ratio (&groupdiff) &var" ; RUN; proc sql; create table combine1 as select * from combine where stddiff>=&rsptobs; create table combine2 as select * from combine where stddiff <= &rsptobs; quit; data _null_; file print; pvalue=2*min(%nobs(combine1), %nobs(combine2))/&nrun; put /@5 "Hypothesis Test With Bootstrap for Testing Equality of Means"; put @5 "No Assumption of Equal Variances"; put @5 76*"="/; put @5 "Reference: Bradley Efron and Andersen J. Tibshirani (1998) An Introduction to"/ @5 "Bootstrap. P224"/; put @5 "Two Sided Bootstrap P Value: " @45 pvalue 20.6 "; "/; run; proc sql; drop table intmp; drop table summary0; drop table combine; drop table outdiff; drop table outf; drop table combine1; drop table combine2; QUIT; %MEND printout;